package com.yisingle.study.map.one.utils;


import android.os.Handler;
import android.os.Message;
import android.util.Log;

/**
 * @author jikun
 *         Created by jikun on 2018/3/14.
 */

public class DelayTest {
    public OnCallBack callBack;

    public Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (null != callBack) {
                callBack.onSuccess();
            }
        }
    };

    public void getDelayPost(OnCallBack callBack) {
        this.callBack = callBack;
        long sec = (long) (Math.random() * 1300);
        Log.e("测试代码", "测试代码时间=" + sec);
        handler.sendEmptyMessageDelayed(0, sec);
    }

    public void stop() {
        this.callBack = null;
    }

    public interface OnCallBack {
        void onSuccess();

        void onFailed();
    }

    public void destory() {
        handler.removeCallbacksAndMessages(null);
    }
}
